package com.djinfo.work.dao.impl;

import com.djinfo.work.common.dao.impl.BaseDaoImpl;
import com.djinfo.work.dao.QsResultDao;
import com.djinfo.work.entity.QsResultEntity;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 *
 * @date 2017-06-08 10:48:16
 */
@Repository("QsResultDao")
public class QsResultDaolmpl extends BaseDaoImpl implements QsResultDao {

    @Override
    public void save(QsResultEntity object) {
        if(null==object.getId()){
            super.save(object);
        }else{
            super.update(object);
        }
    }

    @Override
    public void update(QsResultEntity qsResultEntity) {
        super.update(qsResultEntity);
    }

    @Override
    public QsResultEntity selectOne(String id) {
        return (QsResultEntity)super.getByPrimaryKey(QsResultEntity.class,id);
    }

    @Override
    public void delete(String id) {
        QsResultEntity qsResultEntity = (QsResultEntity)super.getByPrimaryKey(QsResultEntity.class,id);
        super.delete(qsResultEntity);
    }

    @Override
    public List<QsResultEntity> page(QsResultEntity object, Integer pageNum, Integer pageSize) {
        String hql="";
        if(object.getValue()==""||object.getValue()==null){
            hql = " from QsResultEntity where 1=1 ";
        }else {
            hql = " from QsResultEntity where value like '%"+ object.getValue()+ "%'";
        }
        return (List<QsResultEntity>)super.pageQuery( hql,  pageNum,  pageSize);
    }

    @Override
    public Integer getRowCount(QsResultEntity object) {
        String hql="";
        if(object.getValue()==""||object.getValue()==null){
            hql = "select count(*) from QsResultEntity where 1=1 ";
        }else {
            hql = "select count(*) from QsResultEntity where value like '%"+ object.getValue()+ "%'";
        }
        return super.getUniqueObject(hql).hashCode();
    }

    @Override
    public List<QsResultEntity> getList(String hql, String uid, String contentId) {
        return super.getList(hql,uid,contentId);
    }

    @Override
    public void deleteResultByUserIdAndQuestionId(String hql, Object... objects) {
        super.updateByHQL(hql,objects);
    }

    @Override
    public List<QsResultEntity> getQsResultListByQsId(String hql) {

        List<QsResultEntity> list=super.getList(hql);
        return list;
    }

}
